import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:flutter/foundation.dart';

/// 获取审图号
/// 这里设计的很奇怪，当地图创建后才知道这个号码，但是这个号码不一定要显示在地图之上，却一定要显示在app之内，主要是和上架后的合规有关
class AMapApprovalNumber {
  static String? mapContentApprovalNumber;
  static String? satelliteImageApprovalNumber;

  static Function(String? mapContentApprovalNumber,
      String? satelliteImageApprovalNumber)? _listener;

  static void addListener(
      Function(String? mapContentApprovalNumber,
              String? satelliteImageApprovalNumber)
          run) {
    _listener = run;
  }

  static void setApprovalNumber(AMapController? mapController) async {
    //普通地图审图号
    mapContentApprovalNumber =
        await mapController?.getMapContentApprovalNumber();
    //卫星地图审图号
    satelliteImageApprovalNumber =
        await mapController?.getSatelliteImageApprovalNumber();

    if (kDebugMode) {
      print('地图审图号（普通地图）: $mapContentApprovalNumber');
      print('地图审图号（卫星地图): $satelliteImageApprovalNumber');
    }

    if (_listener != null)
      _listener!(mapContentApprovalNumber, satelliteImageApprovalNumber);
  }
}
